package com.common.core.base;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.core.R;
import com.common.core.view.CircularProgress;

/**
 * Created by haitian on 16/5/14.
 */
public abstract class CommonEmptyView extends LinearLayout implements View.OnClickListener {

    protected ImageView ivIcon;
    protected TextView tvTitle;
    protected TextView tvContent;

    protected CircularProgress progress;
    protected OnReloadListener listener;

    public enum LoadingState {
        EMPTY, NET_NOT_AVAILABLE, LOADING, LOADING_ERROR, NORMAL,
    }

    public CommonEmptyView (Context context) {
        this(context, null);
    }

    public CommonEmptyView (Context context, AttributeSet attrs) {
        super(context, attrs);
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        setBackgroundColor(context.getResources().getColor(R.color.white));
        inflate(context, R.layout.view_empty, this);

        ivIcon = (ImageView) findViewById(R.id.view_empty_tip_icon);
        tvTitle = (TextView) findViewById(R.id.view_empty_tip_title);
        tvContent = (TextView) findViewById(R.id.view_empty_tip_content);
        progress = (CircularProgress) findViewById(R.id.view_empty_tip_progress);
        setLoadingState("", LoadingState.LOADING);
        //todo 为了测试方便线隐藏起来了
        this.setVisibility(GONE);
    }

    public void setOnReloadListener(OnReloadListener listener) {
        this.listener = listener;
    }
    public abstract void setLoadingState(String tag, LoadingState state);
    protected abstract void setEmpty(String tag);
    @Override
    public void onClick(View v) {
        if (v == this) {
            if (listener != null) {
                listener.onReloadClick();
            } else {
                throw new RuntimeException("The OnReloadListener is null!!!");
            }
        }
    }

    public interface OnReloadListener {
        void onReloadClick ();
    }
}
